/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogSelectAccount.java
 *
 * Created on 08.06.2011, 14:58:33
 */
package ru.icq.gui.dialogs;

import java.awt.CardLayout;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import org.apache.log4j.Logger;
import ru.icq.gui.dialogs.Renderer.IconListRenderer;
import ru.icq.io.loadTheme;

/**
 * Мастер настройки аккаунтов.
 * @author Носов А.В.
 */
public class DialogSelectAccount_old extends javax.swing.JDialog {

    // Variables declaration
    private static final Logger log = Logger.getLogger(DialogSelectAccount_old.class);
    
    private DefaultListModel modelList;
    private loadTheme theme;
    
    private final short FIRST_CARD = -1;
    private final short ICQ_CARD = 0;
    private final short JABBER_CARD = 1;
    private final short VK_CARD = 2;
    // End of variables declaration

    /** Creates new form DialogSelectAccount */
    public DialogSelectAccount_old(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        theme = new loadTheme("Default", "Russian");
        initComponents();
        
        theme.setTheme( (Component)this );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        panelSelect = new javax.swing.JPanel();
        panelSelectAccount = new javax.swing.JPanel();
        panelFirst = new javax.swing.JPanel();
        labelFirstName = new javax.swing.JLabel();
        textAreaFirstText = new javax.swing.JTextArea();
        scrollPaneListAccounts = new javax.swing.JScrollPane();
        modelList = new DefaultListModel();
        listAccounts = new javax.swing.JList();
        panelSettingsICQ = new javax.swing.JPanel();
        panelICQInfo = new javax.swing.JPanel();
        panelSettingsJabber = new javax.swing.JPanel();
        panelJabberInfo = new javax.swing.JPanel();
        textAreaJabber = new javax.swing.JTextArea();
        jTextArea1 = new javax.swing.JTextArea();
        panelJabberData = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();
        panelSettingsVK = new javax.swing.JPanel();
        panelVKInfo = new javax.swing.JPanel();
        panelSelectButtons = new javax.swing.JPanel();
        panelAccountButtons = new javax.swing.JPanel();
        buttonSelectBack = new javax.swing.JButton();
        buttonSelectForward = new javax.swing.JButton();
        buttonSelectCansel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("dialogSelect"); // NOI18N

        panelSelect.setBorder(javax.swing.BorderFactory.createEmptyBorder(15, 25, 5, 25));
        panelSelect.setLayout(new java.awt.CardLayout());

        panelSelectAccount.setLayout(new java.awt.BorderLayout());

        panelFirst.setLayout(new java.awt.GridLayout(2, 1, 5, 5));

        labelFirstName.setFont(new java.awt.Font("Times New Roman", 1, 24));
        labelFirstName.setText("Protocol");
        labelFirstName.setName("account.firstName"); // NOI18N
        panelFirst.add(labelFirstName);

        textAreaFirstText.setBackground(labelFirstName.getBackground());
        textAreaFirstText.setColumns(20);
        textAreaFirstText.setEditable(false);
        textAreaFirstText.setFont(new java.awt.Font("Times New Roman", 0, 14));
        textAreaFirstText.setLineWrap(true);
        textAreaFirstText.setRows(3);
        textAreaFirstText.setTabSize(0);
        textAreaFirstText.setText("Need text");
        textAreaFirstText.setName("account.firstText"); // NOI18N
        panelFirst.add(textAreaFirstText);

        panelSelectAccount.add(panelFirst, java.awt.BorderLayout.PAGE_START);

        listAccounts.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        listAccounts.setModel(getList());
        listAccounts.setCellRenderer(new IconListRenderer(getIcon()));
        scrollPaneListAccounts.setViewportView(listAccounts);

        panelSelectAccount.add(scrollPaneListAccounts, java.awt.BorderLayout.CENTER);

        panelSelect.add(panelSelectAccount, "first");

        panelSettingsICQ.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout panelICQInfoLayout = new javax.swing.GroupLayout(panelICQInfo);
        panelICQInfo.setLayout(panelICQInfoLayout);
        panelICQInfoLayout.setHorizontalGroup(
            panelICQInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 523, Short.MAX_VALUE)
        );
        panelICQInfoLayout.setVerticalGroup(
            panelICQInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 244, Short.MAX_VALUE)
        );

        panelSettingsICQ.add(panelICQInfo, java.awt.BorderLayout.CENTER);

        panelSelect.add(panelSettingsICQ, "icq");

        panelSettingsJabber.setLayout(new javax.swing.BoxLayout(panelSettingsJabber, javax.swing.BoxLayout.Y_AXIS));

        textAreaJabber.setColumns(1);
        textAreaJabber.setRows(1);
        textAreaJabber.setTabSize(0);
        textAreaJabber.setText("no text");

        jTextArea1.setColumns(1);
        jTextArea1.setRows(3);
        jTextArea1.setTabSize(0);
        jTextArea1.setText("no text");

        javax.swing.GroupLayout panelJabberInfoLayout = new javax.swing.GroupLayout(panelJabberInfo);
        panelJabberInfo.setLayout(panelJabberInfoLayout);
        panelJabberInfoLayout.setHorizontalGroup(
            panelJabberInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelJabberInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelJabberInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextArea1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textAreaJabber, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE))
                .addContainerGap(156, Short.MAX_VALUE))
        );
        panelJabberInfoLayout.setVerticalGroup(
            panelJabberInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelJabberInfoLayout.createSequentialGroup()
                .addComponent(textAreaJabber, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(107, Short.MAX_VALUE))
        );

        panelSettingsJabber.add(panelJabberInfo);

        panelJabberData.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("jLabel1");
        panelJabberData.add(jLabel1, new java.awt.GridBagConstraints());

        jTextField1.setText("jTextField1");
        panelJabberData.add(jTextField1, new java.awt.GridBagConstraints());

        jLabel2.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        panelJabberData.add(jLabel2, gridBagConstraints);

        jPasswordField1.setText("jPasswordField1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        panelJabberData.add(jPasswordField1, gridBagConstraints);

        panelSettingsJabber.add(panelJabberData);

        panelSelect.add(panelSettingsJabber, "jabber");

        panelSettingsVK.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout panelVKInfoLayout = new javax.swing.GroupLayout(panelVKInfo);
        panelVKInfo.setLayout(panelVKInfoLayout);
        panelVKInfoLayout.setHorizontalGroup(
            panelVKInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 523, Short.MAX_VALUE)
        );
        panelVKInfoLayout.setVerticalGroup(
            panelVKInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 244, Short.MAX_VALUE)
        );

        panelSettingsVK.add(panelVKInfo, java.awt.BorderLayout.CENTER);

        panelSelect.add(panelSettingsVK, "vk");
        panelSettingsVK.getAccessibleContext().setAccessibleName("vk");

        getContentPane().add(panelSelect, java.awt.BorderLayout.CENTER);

        panelSelectButtons.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 25, 5, 25));
        panelSelectButtons.setLayout(new java.awt.BorderLayout());

        panelAccountButtons.setLayout(new java.awt.GridBagLayout());

        buttonSelectBack.setText("Back");
        buttonSelectBack.setEnabled(false);
        buttonSelectBack.setName("account.back"); // NOI18N
        buttonSelectBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectBackActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        panelAccountButtons.add(buttonSelectBack, gridBagConstraints);

        buttonSelectForward.setText("Forward");
        buttonSelectForward.setName("account.forward"); // NOI18N
        buttonSelectForward.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectForwardActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        panelAccountButtons.add(buttonSelectForward, gridBagConstraints);

        buttonSelectCansel.setText("Cansel");
        buttonSelectCansel.setName("account.cansel"); // NOI18N
        buttonSelectCansel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSelectCanselActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        panelAccountButtons.add(buttonSelectCansel, gridBagConstraints);

        panelSelectButtons.add(panelAccountButtons, java.awt.BorderLayout.LINE_END);

        getContentPane().add(panelSelectButtons, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonSelectBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectBackActionPerformed
        visibleCard(-1);
    }//GEN-LAST:event_buttonSelectBackActionPerformed

    private void buttonSelectForwardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectForwardActionPerformed
        visibleCard(listAccounts.getSelectedIndex());
    }//GEN-LAST:event_buttonSelectForwardActionPerformed

    private void buttonSelectCanselActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectCanselActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_buttonSelectCanselActionPerformed

    /**
     * Возвращает список аккаунтов, которые можно создать.
     * @return список аккаунтов
     */
    private DefaultListModel getList() {
        modelList.addElement("ICQ");
        modelList.addElement("Jabber");
        modelList.addElement("VKontakte");
        return modelList;
    }

    /**
     * Возвращает список иконок, для аккаунтов.
     * @return список иконок
     */
    private Map<Object, Icon> getIcon() {
        Map<Object, Icon> icons = new HashMap<Object, Icon>();
        icons.put("ICQ", theme.getIcon("account.icq"));
        icons.put("Jabber", theme.getIcon("account.jabber"));
        icons.put("VKontakte", theme.getIcon("account.vkontakte"));
        return icons;
    }

    private void visibleCard(int selectCard) {
        buttonSelectBack.setEnabled(true);
        CardLayout cl = (CardLayout)panelSelect.getLayout();
        switch (selectCard) {
            case FIRST_CARD:
                buttonSelectBack.setEnabled(false);
                cl.show(panelSelect, "first");
                break;
            case ICQ_CARD:
                cl.show(panelSelect, "icq");
                break;
            case JABBER_CARD:
                cl.show(panelSelect, "jabber");
                break;
            case VK_CARD:
                cl.show(panelSelect, "vk");
                break;
            default:
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                DialogSelectAccount_old dialog = new DialogSelectAccount_old(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonSelectBack;
    private javax.swing.JButton buttonSelectCansel;
    private javax.swing.JButton buttonSelectForward;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JLabel labelFirstName;
    private javax.swing.JList listAccounts;
    private javax.swing.JPanel panelAccountButtons;
    private javax.swing.JPanel panelFirst;
    private javax.swing.JPanel panelICQInfo;
    private javax.swing.JPanel panelJabberData;
    private javax.swing.JPanel panelJabberInfo;
    private javax.swing.JPanel panelSelect;
    private javax.swing.JPanel panelSelectAccount;
    private javax.swing.JPanel panelSelectButtons;
    private javax.swing.JPanel panelSettingsICQ;
    private javax.swing.JPanel panelSettingsJabber;
    private javax.swing.JPanel panelSettingsVK;
    private javax.swing.JPanel panelVKInfo;
    private javax.swing.JScrollPane scrollPaneListAccounts;
    private javax.swing.JTextArea textAreaFirstText;
    private javax.swing.JTextArea textAreaJabber;
    // End of variables declaration//GEN-END:variables
}
